<%-- 
    Document   : download_submission
    Created on : 2011年8月27日, 上午09:58:44
    Author     : Terry
--%>

<%@page import="unilearn.vo.Role"%>
<%@page import="unilearn.vo.Person"%>
<%@page import="unilearn.bo.AccessValidator"%>
<%@page import="unilearn.bo.SubjectManagement"%>
<%@page import="unilearn.vo.Submission"%>
<%@page import="unilearn.vo.Assignment"%>
<%@page import="unilearn.bo.AssignmentManagement"%>
<%@page import="unilearn.dao.AssignmentDAO"%>
<%@page import="unilearn.vo.Subject"%>
<%@page import="java.util.List"%>
<%@page import="unilearn.dao.SubjectDAO"%>
<%@page import="unilearn.bo.SubmissionManagement"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
        <%            
            WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
            SubmissionManagement submMgt = (SubmissionManagement) context.getBean("submMgt");
            AccessValidator vaildater = (AccessValidator) context.getBean("accessValidator");
            SubjectManagement subjectMgt = (SubjectManagement) context.getBean("subjectMgt");
            AssignmentManagement assignMgt = (AssignmentManagement) context.getBean("assignMgt");

            HttpSession s = request.getSession();

            Person person = (Person) s.getAttribute("person");
            Role role = (Role) s.getAttribute("role");
            String assignType = "I";
            List<Subject> subs = null;
            if (role.getName().equals("student")) {
                subs = subjectMgt.getStudentSubjects(person);
            } else if (role.getName().equals("staff")) {                       
            } else if (role.getName().equals("lecturer")) {
                subs = subjectMgt.getConvernorSubjects(person);
                subs.addAll(subjectMgt.getMarkerSubjects(person));
            } else if (role.getName().equals("administrator")) {
            }
                        
            if (subs == null) {
                return;
            }

           for (Subject sub : subs) {
                List<Assignment> assigns = assignMgt.getAssignments(sub);
                if (assigns == null) {
                    break;
                }     

                if (sub.getSubjectCode().equals((String)request.getParameter("subject")) ){                    
                    for (Assignment assign : assigns) {
                        if (assign.getId().equals((String)request.getParameter("Assignment")) ){
                           assignType = assign.getType();
                        }              
                    }
                }                                                                                   
            }
                //person.getId()
            if (role.getName().equals("student")){
                if (assignType.equals("I")){
                    out.print("<input  type=\"hidden\" id=\"autor_id\" value=\"" +person.getId() + "\" />");
                } else{
                    out.print("<input  type=\"hidden\" id=\"autor_id\" value=\"" +person.getId() + "\" />");
                }             
                out.print("<input  type=\"hidden\" id=\"assignId\" value=\"" +(String)request.getParameter("Assignment") + "\" />");
                out.print("<p><a  onclick=\"subassignment()\" > Assignment Submit</a>");  
                out.print("<p><a  onclick=\"ControlPanel('view_marks_panel')\" > View Marks</a>");                                               
            }else if (role.getName().equals("lecturer")){            
                out.print("<p><a  onclick=\"ControlPanel('marking_control')\" > Marking</a>"); 
                out.print("<p><a  onclick=\"ControlPanel('view_report_panel')\" > Report</a>");             
            }
        %>
